package com.sunsheng.modules.redis.service.impl;

import com.sunsheng.modules.redis.service.MQService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Slf4j
@Service
public class MQServiceImpl implements MQService {

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public void produce(String topic, String string) {
        redisTemplate.opsForList().leftPush(topic, string);
    }

    @Override
    public void consume(String topic) {
        String string = (String) redisTemplate.opsForList().rightPop(topic);
        log.info("消费一个消息 : {}", string);
    }

}
